#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <conio.c>
#include <time.h>

typedef struct space {
    void campo();

    typedef struct tiro {
        bool tbool;
        int posx;
        int posy;
        int tempo_tiro;
        bool pbool;
        int poox;
        int pooy;
        int tempo_cagada;
    };
    int c1, c2, l1, l2, l3, l4, l5;
    void invaders();

    typedef struct sinvader {
        int invx, invy;
        bool inv;
        int cond;
    };
    tiro vetor_tiro[20];
    tiro vetor_poo[3];
    sinvader vetor_invader[40];
    int qnt_inv;
    int poo1, poo2, poo0;
    bool esquerda, direita;
    bool descer_esquerda, descer_direita;
    bool fase1, fase2, fase3, fase4;
    char matriz_invader[20][50];
    int x, y, enemy, score, cont, cont_inv;
    int tempo_mov, tempo;
    char tecla;
    void atribuicao();
    void cagando();
    void cagar();
    int teclas();
    void menu();
    void movimento();
    void jscore();
    void loop_jogo();
    void abertura();
    void foguetar();
    void fase02();
};

void space::atribuicao() {
    l1 = 4;
    l2 = 6;
    l3 = 8;
    l4 = 10;
    l5 = 12;
    x = 30;
    y = 18;
    enemy = 3;
    score = 1000;
    cont = 0;
    qnt_inv = 0;
    for (int i = 0; i <= 40; i++) {
        vetor_invader[i].inv = false;
        vetor_invader[i].invy = 0;
        vetor_invader[i].invx = 0;
    }
    direita = true;
    esquerda = false;
    descer_direita = true;
    descer_esquerda = false;
    fase1 = true;
    fase2 = fase3 = fase4 = false;
    for (int i = 0; i <= 20; i++) {
        vetor_tiro[i].tbool = false;
        vetor_tiro[i].tempo_tiro = 0;
    }
    for (int p = 0; p <= 3; p++) {
        vetor_poo[p].pbool = false;
        vetor_poo[p].tempo_cagada = 0;
    }
}

void space::campo() {
    textcolor(LIGHTBLUE);
    int c;
    for (c = 0; c < 50; c++) {
        gotoxy(c, 1);
        printf("%c", 178);
    }
    for (c = 2; c <= 20; c++) {
        gotoxy(49, c);
        printf("%c", 178);
    }
    for (c = 2; c < 22; c++) {
        gotoxy(1, c);
        printf("%c", 178);
    }
    for (c = 0; c <= 49; c++) {
        gotoxy(c, 21);
        printf("%c", 178);
    }
}

void space::invaders() {
    textcolor(GREEN);
    int z;
    for (int i = 0; i < 20; i++) {
        for (int j = 0; j < 50; j++) {
            matriz_invader[i][j] = ' ';
        }
    }
    for (c1 = 5; c1 <= 40; c1 = c1 + 5) {
        matriz_invader[l4][c1] = '#';
        vetor_invader[qnt_inv].invy = l4;
        vetor_invader[qnt_inv].invx = c1;
        vetor_invader[qnt_inv].inv = true;
        gotoxy(vetor_invader[qnt_inv].invx, vetor_invader[qnt_inv].invy);
        printf("#");
        qnt_inv++;
    }
    for (c2 = 5; c2 <= 40; c2 = c2 + 5) {
        matriz_invader[l3][c1] = '#';
        vetor_invader[qnt_inv].invy = l3;
        vetor_invader[qnt_inv].invx = c2;
        vetor_invader[qnt_inv].inv = true;
        gotoxy(vetor_invader[qnt_inv].invx, vetor_invader[qnt_inv].invy);
        printf("#");
        qnt_inv++;
    }
    for (c2 = 5; c2 <= 40; c2 = c2 + 5) {
        matriz_invader[l2][c1] = '#';
        vetor_invader[qnt_inv].invy = l2;
        vetor_invader[qnt_inv].invx = c2;
        vetor_invader[qnt_inv].inv = true;
        gotoxy(vetor_invader[qnt_inv].invx, vetor_invader[qnt_inv].invy);
        printf("#");
        qnt_inv++;
    }
    for (c2 = 5; c2 <= 40; c2 = c2 + 5) {
        matriz_invader[l1][c1] = '#';
        vetor_invader[qnt_inv].invy = l1;
        vetor_invader[qnt_inv].invx = c2;
        vetor_invader[qnt_inv].inv = true;
        gotoxy(vetor_invader[qnt_inv].invx, vetor_invader[qnt_inv].invy);
        printf("#");
        qnt_inv++;
    }
    qnt_inv--;
}

int space::teclas() {
    textcolor(LIGHTGRAY);
    if (kbhit()) {
        tecla = getch();
        switch (tecla) {
            case 't':
                score = score + 3200;
                break;
            case 'm':
                system("cls");
                printf(" \tPower Ranger Beta 1 Show Time. Xing_Ling - All Rights Reserved\n\n\t\t\t Agradece a Preferencia");
                _sleep(7500);
                exit(0);
            case 'a':
                if (x == 2) {
                    gotoxy(2, y);
                    printf("%c", 193);
                } else {
                    gotoxy(x, y);
                    printf(" ");
                    x--;
                    gotoxy(x, y);
                    printf("%c", 193);
                }
                break;
            case 'd':
                if (x == 48) {
                    gotoxy(48, y);
                    printf("%c", 193);
                } else {
                    gotoxy(x, y);
                    printf(" ");
                    x++;
                    gotoxy(x, y);
                    printf("%c", 193);
                }
                break;
            case 'w':
                for (int i = 0; i <= 10; i++) {
                    if (vetor_tiro[i].tbool == false) {
                        vetor_tiro[i].tbool = true;
                        vetor_tiro[i].posx = x;
                        vetor_tiro[i].posy = y - 2;
                        vetor_tiro[i].tempo_tiro = clock();
                        break;
                    }
                }
        }
    }
}

void space::foguetar() {
    for (int i = 0; i <= 20; i++) {
        if (clock() > vetor_tiro[i].tempo_tiro) {
            if (vetor_tiro[i].tbool == true) {
                if (vetor_tiro[i].posy > 2) {
                    gotoxy(vetor_tiro[i].posx, vetor_tiro[i].posy);
                    printf("|");
                    if (matriz_invader[vetor_tiro[i].posy + 1][vetor_tiro[i].posx] == '#') {
                        textcolor(GREEN);
                        gotoxy(vetor_tiro[i].posx, vetor_tiro[i].posy + 1);
                        printf("#");
                    } else {
                        gotoxy(vetor_tiro[i].posx, vetor_tiro[i].posy + 1);
                        printf(" ");
                    }
                    vetor_tiro[i].posy--;
                    vetor_tiro[i].tempo_tiro = vetor_tiro[i].tempo_tiro + 75;
					if (matriz_invader[vetor_tiro[i].posy][vetor_tiro[i].posx] == '#') {
                        matriz_invader[vetor_tiro[i].posy][vetor_tiro[i].posx] = ' ';
                        qnt_inv = qnt_inv - 1;
                        for (int k = 0; k <= 31; k++) {
                            if (vetor_invader[k].invx == vetor_tiro[i].posx) {
                                if (vetor_invader[k].invy == vetor_tiro[i].posy) {
                                    vetor_invader[k].inv = false;
                                }
                            }
                        }
                        gotoxy(vetor_tiro[i].posx, vetor_tiro[i].posy);
                        printf(" ");
                        gotoxy(vetor_tiro[i].posx, vetor_tiro[i].posy + 1);
                        printf(" ");
                        score = score + 100;
                        vetor_tiro[i].posy = 2;
                    }
                }
                if (vetor_tiro[i].posy == 2) {
                    gotoxy(vetor_tiro[i].posx, vetor_tiro[i].posy + 1);
                    printf(" ");
                    vetor_tiro[i].tbool = false;
                }
            }
        }
    }
}

void space::cagar() {
    textcolor(YELLOW);
    for (int i = 0; i <= 3; i++) {
        if (clock() > vetor_poo[i].tempo_cagada) {
            if (vetor_poo[i].pbool == true) {
                if (vetor_poo[i].pooy < 20) {
                    gotoxy(vetor_poo[i].poox, vetor_poo[i].pooy);
                    printf("|");
                    gotoxy(vetor_poo[i].poox, vetor_poo[i].pooy - 1);
                    printf(" ");
                    vetor_poo[i].pooy++;
                    if (fase1 == true) {
                        vetor_poo[i].tempo_cagada = vetor_poo[i].tempo_cagada + 190;
                    }
                    if (fase2 == true) {
                        vetor_poo[i].tempo_cagada = vetor_poo[i].tempo_cagada + 120;
                    }
                    if (fase3 == true) {
                        vetor_poo[i].tempo_cagada = vetor_poo[i].tempo_cagada + 100;
                    }
                    if (fase4 == true) {
                        vetor_poo[i].tempo_cagada = vetor_poo[i].tempo_cagada + 75;
                    }
                    if (vetor_poo[i].pooy == y) {
                        if (vetor_poo[i].poox == x) {
                            enemy--;
                            jscore();
                        }
                    }
                }
                if (vetor_poo[i].pooy == 20) {
                    gotoxy(vetor_poo[i].poox, vetor_poo[i].pooy - 1);
                    printf(" ");
                    vetor_poo[i].pbool = false;
                    break;
                }
            }
        }
    }
}

void space::cagando() {
    textcolor(YELLOW);
    if (vetor_poo[0].pbool == false) {
        vetor_poo[0].pbool = true;
        poo0 = rand() % 7;
        if (vetor_invader[poo0].inv == false) {
            poo0 = poo0 + 8;
            if (vetor_invader[poo0].inv == false) {
                poo0 = poo0 + 8;
                if (vetor_invader[poo0].inv == false) {
                    poo0 = poo0 + 8;
                    if (vetor_invader[poo0].inv == false) {
                        vetor_poo[0].pbool = false;
                    }
                }
            }
        }
        vetor_poo[0].poox = vetor_invader[poo0].invx;
        vetor_poo[0].pooy = vetor_invader[poo0].invy + 2;
        vetor_poo[0].tempo_cagada = clock() + 500;
    }
    if (vetor_poo[1].pbool == false) {
        poo1 = rand() % 7;
        vetor_poo[1].pbool = true;
        if (vetor_invader[poo1].inv == false) {
            poo1 = poo1 + 8;
            if (vetor_invader[poo1].inv == false) {
                poo1 = poo1 + 8;
                if (vetor_invader[poo1].inv == false) {
                    poo1 = poo1 + 8;
                    if (vetor_invader[poo1].inv == false) {
                        vetor_poo[1].pbool = false;
                    }
                }
            }
        }
        vetor_poo[1].poox = vetor_invader[poo1].invx;
        vetor_poo[1].pooy = vetor_invader[poo1].invy + 2;
        vetor_poo[1].tempo_cagada = clock() + 900;
    }
    if (vetor_poo[2].pbool == false) {
        poo2 = rand() % 7;
        vetor_poo[2].pbool = true;
        if (vetor_invader[poo2].inv == false) {
            poo2 = poo2 + 8;
            if (vetor_invader[poo2].inv == false) {
                poo2 = poo2 + 8;
                if (vetor_invader[poo2].inv == false) {
                    poo2 = poo2 + 8;
                    if (vetor_invader[poo2].inv == false) {
                        vetor_poo[2].pbool = false;
                    }
                }
            }
        }
        vetor_poo[2].poox = vetor_invader[poo2].invx;
        vetor_poo[2].pooy = vetor_invader[poo2].invy + 2;
        vetor_poo[2].tempo_cagada = clock() + 100;
    }
}

void space::movimento() {
    textcolor(GREEN);
    if (clock() > tempo_mov) {
        for (int k = 0; k <= 31; k++) {
            if (vetor_invader[k].invy == (y-1)) {
                enemy = 0;
            }
        }
        if (esquerda == true) {
            for (int m = 0; m <= 31; m++) {
                if (vetor_invader[m].inv == true) {
                    matriz_invader[vetor_invader[m].invy][vetor_invader[m].invx] = ' ';
                    gotoxy(vetor_invader[m].invx, vetor_invader[m].invy);
                    printf(" ");
                    vetor_invader[m].invx = vetor_invader[m].invx - 1;
                    matriz_invader[vetor_invader[m].invy][vetor_invader[m].invx] = '#';
                    gotoxy(vetor_invader[m].invx, vetor_invader[m].invy);
                    printf("#");
                }
            }
        }
        if (direita == true) {
            for (int m = 0; m <= 31; m++) {
                if (vetor_invader[m].inv == true) {
                    matriz_invader[vetor_invader[m].invy][vetor_invader[m].invx] = ' ';
                    gotoxy(vetor_invader[m].invx, vetor_invader[m].invy);
                    printf(" ");
                    vetor_invader[m].invx = vetor_invader[m].invx + 1;
                    matriz_invader[vetor_invader[m].invy][vetor_invader[m].invx] = '#';
                    gotoxy(vetor_invader[m].invx, vetor_invader[m].invy);
                    printf("#");
                }
            }
        }
        for (int a = 0; a <= 31; a++) {
            if (vetor_invader[a].inv == true) {
                if (vetor_invader[a].invx == 47) {
                    if (descer_direita == true) {
                        direita = false;
                        esquerda = true;
                        descer_direita = false;
                        descer_esquerda = true;
                        for (int m = 0; m <= 31; m++) {
                            if (vetor_invader[m].inv == true) {
                                matriz_invader[vetor_invader[m].invy][vetor_invader[m].invx] = ' ';
                                gotoxy(vetor_invader[m].invx, vetor_invader[m].invy);
                                printf(" ");
                                vetor_invader[m].invy = vetor_invader[m].invy + 1;
                                matriz_invader[vetor_invader[m].invy][vetor_invader[m].invx] = '#';
                                gotoxy(vetor_invader[m].invx, vetor_invader[m].invy);
                                printf("#");
                            }
                        }
                    }
                }
            }
        }
        for (int a = 0; a <= 31; a++) {
            if (vetor_invader[a].inv == true) {
                if (vetor_invader[a].invx == 3) {
                    if (descer_esquerda == true) {
                        direita = true;
                        esquerda = false;
                        descer_esquerda = false;
                        descer_direita = true;
                        for (int m = 0; m <= 31; m++) {
                            if (vetor_invader[m].inv == true) {
                                matriz_invader[vetor_invader[m].invy][vetor_invader[m].invx] = ' ';
                                gotoxy(vetor_invader[m].invx, vetor_invader[m].invy);
                                printf(" ");
                                vetor_invader[m].invy = vetor_invader[m].invy + 1;
                                matriz_invader[vetor_invader[m].invy][vetor_invader[m].invx] = '#';
                                gotoxy(vetor_invader[m].invx, vetor_invader[m].invy);
                                printf("#");
                            }
                        }
                    }
                }
            }
        }
        if (fase1 == true) {
            tempo_mov = tempo_mov + 1200;
        }
        if (fase2 == true) {
            tempo_mov = tempo_mov + 900;
        }
        if (fase3 == true) {
            tempo_mov = tempo_mov + 600;
        }
        if (fase4 == true) {
            tempo_mov = tempo_mov + 300;
        }
    }
}

void space::jscore() {
    textcolor(LIGHTBLUE);
    gotoxy(63, 2);
    printf("Score: %d", score);
    gotoxy(63, 4);
    printf("Continue: %d", enemy);
    gotoxy(63, 6);
    printf("Tempo de jogo %d", clock() / 1000);
    gotoxy(63, 8);
    printf("invasores: %d", qnt_inv);
}

void space::fase02() {

    l1 = 4;
    l2 = 6;
    l3 = 8;
    l4 = 10;
    l5 = 12;
    x = 30;
    y = 18;
    enemy = enemy;
    score = score;
    cont = 0;
    tempo_mov = tempo_mov - 300;
    qnt_inv = 0;
    for (int i = 0; i <= 40; i++) {
        vetor_invader[i].inv = false;
        vetor_invader[i].invy = 0;
        vetor_invader[i].invx = 0;
    }
    direita = true;
    esquerda = false;
    descer_direita = true;
    descer_esquerda = false;

    for (int i = 0; i <= 20; i++) {
        vetor_tiro[i].tbool = false;
        vetor_tiro[i].tempo_tiro = 0;
    }
    for (int p = 0; p <= 3; p++) {
        vetor_poo[p].pbool = false;
        vetor_poo[p].tempo_cagada = 0;
    }
    textcolor(GREEN);
    int z;
    for (int i = 0; i < 20; i++) {
        for (int j = 0; j < 50; j++) {
            matriz_invader[i][j] = ' ';
        }
    }
    for (c1 = 5; c1 <= 40; c1 = c1 + 5) {
        matriz_invader[l4][c1] = '#';
        vetor_invader[qnt_inv].invy = l4;
        vetor_invader[qnt_inv].invx = c1;
        vetor_invader[qnt_inv].inv = true;
        gotoxy(vetor_invader[qnt_inv].invx, vetor_invader[qnt_inv].invy);
        printf("#");
        qnt_inv++;
    }
    for (c2 = 5; c2 <= 40; c2 = c2 + 5) {
        matriz_invader[l3][c1] = '#';
        vetor_invader[qnt_inv].invy = l3;
        vetor_invader[qnt_inv].invx = c2;
        vetor_invader[qnt_inv].inv = true;
        gotoxy(vetor_invader[qnt_inv].invx, vetor_invader[qnt_inv].invy);
        printf("#");
        qnt_inv++;
    }
    for (c2 = 5; c2 <= 40; c2 = c2 + 5) {
        matriz_invader[l2][c1] = '#';
        vetor_invader[qnt_inv].invy = l2;
        vetor_invader[qnt_inv].invx = c2;
        vetor_invader[qnt_inv].inv = true;
        gotoxy(vetor_invader[qnt_inv].invx, vetor_invader[qnt_inv].invy);
        printf("#");
        qnt_inv++;
    }
    for (c2 = 5; c2 <= 40; c2 = c2 + 5) {
        matriz_invader[l1][c1] = '#';
        vetor_invader[qnt_inv].invy = l1;
        vetor_invader[qnt_inv].invx = c2;
        vetor_invader[qnt_inv].inv = true;
        gotoxy(vetor_invader[qnt_inv].invx, vetor_invader[qnt_inv].invy);
        printf("#");
        qnt_inv++;
    }
    qnt_inv--;
    textcolor(LIGHTBLUE);
    int c;
    for (c = 0; c < 50; c++) {
        gotoxy(c, 1);
        printf("%c", 178);
    }
    for (c = 2; c <= 20; c++) {
        gotoxy(49, c);
        printf("%c", 178);
    }
    for (c = 2; c < 22; c++) {
        gotoxy(1, c);
        printf("%c", 178);
    }
    for (c = 0; c <= 49; c++) {
        gotoxy(c, 21);
        printf("%c", 178);
    }
    textcolor(LIGHTBLUE);
    gotoxy(63, 2);
    printf("Score: %d", score);
    gotoxy(63, 4);
    printf("Continue: %d", enemy);
    gotoxy(63, 6);
    printf("Cont %d", cont);
    gotoxy(63, 8);
    printf("Tempo de jogo %d", clock() / 1000);
    gotoxy(63, 10);
    printf("Tempo %d", tempo);
    gotoxy(63, 12);
    printf("invasores: %d", qnt_inv);
}

void space::menu() {
    {
        textcolor(LIGHTGRAY);
        char op;
        int i, j, k = 178;
        int si[7][57] = {
            //  1   2   3   4   5   6   7   8   9   10  11  12  13  14  15  16  17  18  19  20  21  22  23  24  25  26  27  28  29  30  31  32  33  34  35  36  37  38  39  40  41  42  43  44  45  46  47  48  49  50  51  52  53  54  55  56  57                                             
            {178, 178, 178, 200, 178, 178, 178, 200, 178, 178, 178, 200, 178, 178, 178, 200, 178, 178, 178, 200, 200, 200, 178, 178, 178, 200, 178, 178, 200, 200, 178, 200, 178, 200, 200, 200, 178, 200, 178, 178, 178, 200, 178, 178, 200, 200, 178, 178, 178, 200, 178, 178, 178, 200, 178, 178, 178},
            {178, 200, 200, 200, 178, 200, 178, 200, 178, 200, 178, 200, 178, 200, 200, 200, 178, 200, 200, 200, 200, 200, 200, 178, 200, 200, 178, 178, 200, 200, 178, 200, 178, 200, 200, 200, 178, 200, 178, 200, 178, 200, 178, 200, 178, 200, 178, 200, 200, 200, 178, 200, 178, 200, 178, 200, 200},
            {178, 200, 200, 200, 178, 200, 178, 200, 178, 200, 178, 200, 178, 200, 200, 200, 178, 200, 200, 200, 200, 200, 200, 178, 200, 200, 178, 200, 178, 200, 178, 200, 178, 200, 200, 200, 178, 200, 178, 200, 178, 200, 178, 200, 178, 200, 178, 200, 200, 200, 178, 200, 178, 200, 178, 200, 200},
            {178, 178, 178, 200, 178, 178, 178, 200, 178, 178, 178, 200, 178, 200, 200, 200, 178, 178, 200, 200, 200, 200, 200, 178, 200, 200, 178, 200, 178, 200, 178, 200, 200, 178, 200, 178, 200, 200, 178, 178, 178, 200, 178, 200, 178, 200, 178, 178, 200, 200, 178, 178, 178, 200, 178, 178, 178},
            {200, 200, 178, 200, 178, 200, 200, 200, 178, 200, 178, 200, 178, 200, 200, 200, 178, 200, 200, 200, 200, 200, 200, 178, 200, 200, 178, 200, 200, 178, 178, 200, 200, 178, 200, 178, 200, 200, 178, 200, 178, 200, 178, 200, 178, 200, 178, 200, 200, 200, 178, 178, 200, 200, 200, 200, 178},
            {200, 200, 178, 200, 178, 200, 200, 200, 178, 200, 178, 200, 178, 200, 200, 200, 178, 200, 200, 200, 200, 200, 200, 178, 200, 200, 178, 200, 200, 178, 178, 200, 200, 178, 200, 178, 200, 200, 178, 200, 178, 200, 178, 200, 178, 200, 178, 200, 200, 200, 178, 200, 178, 200, 200, 200, 178},
            {178, 178, 178, 200, 178, 200, 200, 200, 178, 200, 178, 200, 178, 178, 178, 200, 178, 178, 178, 200, 200, 200, 178, 178, 178, 200, 178, 200, 200, 200, 178, 200, 200, 200, 178, 200, 200, 200, 178, 200, 178, 200, 178, 178, 200, 200, 178, 178, 178, 200, 178, 200, 178, 200, 178, 178, 178},
        };

        int bixo[8][8];

        for (int x = 0; x < 8; x++)
            for (int y = 0; y < 8; y++)
                bixo[x][y] = 0;

        bixo[0][3] = 219;
        bixo[0][4] = 219;

        bixo[1][2] = 219;
        bixo[1][3] = 219;
        bixo[1][4] = 219;
        bixo[1][5] = 219;

        bixo[2][1] = 219;
        bixo[2][2] = 219;
        bixo[2][3] = 219;
        bixo[2][4] = 219;
        bixo[2][5] = 219;
        bixo[2][6] = 219;

        bixo[3][0] = 219;
        bixo[3][1] = 219;
        bixo[3][3] = 219;
        bixo[3][4] = 219;
        bixo[3][6] = 219;
        bixo[3][7] = 219;

        for (int x = 0; x < 8; x++)
            bixo[4][x] = 219;

        bixo[5][1] = 219;
        bixo[5][3] = 219;
        bixo[5][4] = 219;
        bixo[5][6] = 219;

        bixo[6][0] = 219;
        bixo[6][7] = 219;

        bixo[7][1] = 219;
        bixo[7][6] = 219;


        do {

            system("cls");
            printf("\n");
            for (i = 0; i < 7; i++) {
                printf("\t  ");
                for (j = 0; j < 57; j++) {
                    if (si[i][j] == 178) {
                        printf("%c", k);
                        _sleep(5);
                    } else {
                        printf(" ");
                        _sleep(5);
                    }
                }
                printf("\n");
                _sleep(60);
            }

            printf("\n");
            for (int x = 0; x < 8; x++) {
                printf("\n\t\t\t\t");
                for (int y = 0; y < 8; y++) {
                    printf("%c", bixo[x][y]);
                    printf("%c", bixo[x][y]);
                }
            }
            printf("\n\n\n\n\t\t\t\t[Pressione Enter]\n\n\t\t    Version Mega Plus ++ Power Ranger Beta 1\n\t\t         Show Time. All Rights Reserved");
            op = getch();
        } while (op != '\r');
        system("cls");
    }
    int BIXO[8][12];

    for (int x = 0; x < 8; x++)
        for (int y = 0; y < 12; y++)
            BIXO[x][y] = 0;

    BIXO[0][4] = 219;
    BIXO[0][5] = 219;
    BIXO[0][6] = 219;
    BIXO[0][7] = 219;

    BIXO[1][1] = 219;
    BIXO[1][2] = 219;
    BIXO[1][3] = 219;
    BIXO[1][4] = 219;
    BIXO[1][5] = 219;
    BIXO[1][6] = 219;
    BIXO[1][7] = 219;
    BIXO[1][8] = 219;
    BIXO[1][9] = 219;
    BIXO[1][10] = 219;

    for (int x = 0; x < 12; x++) {
        BIXO[4][x] = 219;
        BIXO[2][x] = 219;
    }

    BIXO[3][0] = 219;
    BIXO[3][1] = 219;
    BIXO[3][2] = 219;
    BIXO[3][5] = 219;
    BIXO[3][6] = 219;
    BIXO[3][9] = 219;
    BIXO[3][10] = 219;
    BIXO[3][11] = 219;

    BIXO[5][3] = 219;
    BIXO[5][4] = 219;
    BIXO[5][7] = 219;
    BIXO[5][8] = 219;

    BIXO[6][2] = 219;
    BIXO[6][3] = 219;
    BIXO[6][5] = 219;
    BIXO[6][6] = 219;
    BIXO[6][8] = 219;
    BIXO[6][9] = 219;

    BIXO[7][0] = 219;
    BIXO[7][1] = 219;
    BIXO[7][10] = 219;
    BIXO[7][11] = 219;

    printf("\n\n");
    for (int x = 0; x < 8; x++) {
        printf("\n\t\t\t\t  ");
        for (int y = 0; y < 12; y++)
            printf("%c", BIXO[x][y]);
    }
    printf("\n\n");
    int n;
voltar:
    printf("\t\n\n\n\n");
    printf("\t\t\t    ***Escolha uma op%c%co***\n\n ", 135, 198);
    printf("\t\t\t\t   1. Jogar\n");
    printf("\t\t\t\t   2. Sair\n\n");
    scanf("%d", &n);
    printf("\n");
    system("cls");
    switch (n) {
        case 1:
            tempo = clock() + 190;
            tempo_mov = tempo;
            loop_jogo();
            break;
        case 2:
            system("cls");
            printf(" \tPower Ranger Beta 1 Show Time. Xing_Ling - All Rights Reserved\n\n\t\t\t Agradece a Preferencia");
            _sleep(7500);
            exit(0);
            break;
        default:
            printf("\t\t Tente Novamente!");
            menu();
            break;
    }
}

void space::loop_jogo() {
    atribuicao();
    invaders();
    campo();
    jscore();
    textcolor(LIGHTBLUE);
    gotoxy(30, 18);
    cprintf("%c", 193);
    gotoxy(63, 23);
    printf("Sair: M");
    gotoxy(63, 16);
    printf("A <-     -> D");
    gotoxy(63, 18);
    printf("Foguetar W");
    while (score != 100000) {
        textcolor(YELLOW);
        if (score == 4200) {
            fase1 = false;
            fase2 = true;
            score++;
            gotoxy(17, 10);
            printf("***Nova Invasao***");
            system("pause>>NULL");
            system("cls");
            fase02();
        }
        if (score == 7401) {
            fase2 = false;
            fase3 = true;
            score++;
            gotoxy(17, 10);
            printf("***Nova Invasao***");
            system("pause>>NULL");
            system("cls");
            fase02();
        }
        if (score == 10602) {
            fase3 = false;
            fase4 = true;
            score++;
            gotoxy(17, 10);
            printf("***Nova Invasao***");
            system("pause>>NULL");
            system("cls");
            fase02();
        }
        if (enemy == 0) {
            system("cls");
            textcolor(LIGHTGRAY);
            int i, j, k = 178;
            int si[7][57] = {
                //  1   2   3   4   5   6   7   8   9   10  11  12  13  14  15  16  17  18  19  20  21  22  23  24  25  26  27  28  29  30  31  32  33  34  35  36  37  38  39  40  41  42  43  44  45  46  47  48                                                
                {178, 178, 178, 178, 200, 178, 178, 178, 178, 200, 178, 200, 200, 200, 178, 200, 178, 178, 178, 200, 200, 200, 200, 178, 178, 178, 178, 200, 178, 200, 200, 178, 200, 178, 178, 178, 200, 178, 178, 178, 200, 200, 200, 178, 178, 178, 178, 178},
                {178, 200, 200, 200, 200, 178, 200, 200, 178, 200, 178, 178, 200, 178, 178, 200, 178, 200, 200, 200, 200, 200, 200, 178, 200, 200, 178, 200, 178, 200, 200, 178, 200, 178, 200, 200, 200, 178, 200, 200, 178, 200, 200, 200, 178, 178, 178, 200},
                {178, 200, 200, 200, 200, 178, 200, 200, 178, 200, 178, 200, 178, 200, 178, 200, 178, 200, 200, 200, 200, 200, 200, 178, 200, 200, 178, 200, 178, 200, 200, 178, 200, 178, 200, 200, 200, 178, 200, 200, 178, 200, 200, 200, 178, 178, 178, 200},
                {178, 200, 178, 178, 200, 178, 178, 178, 178, 200, 178, 200, 200, 200, 178, 200, 178, 178, 200, 200, 200, 200, 200, 178, 200, 200, 178, 200, 178, 200, 200, 178, 200, 178, 178, 200, 200, 178, 200, 200, 178, 200, 200, 200, 200, 178, 200, 200},
                {178, 200, 200, 178, 200, 178, 200, 200, 178, 200, 178, 200, 200, 200, 178, 200, 178, 200, 200, 200, 200, 200, 200, 178, 200, 200, 178, 200, 178, 200, 200, 178, 200, 178, 200, 200, 200, 178, 178, 178, 200, 200, 200, 200, 200, 178, 200, 200},
                {178, 200, 200, 178, 200, 178, 200, 200, 178, 200, 178, 200, 200, 200, 178, 200, 178, 200, 200, 200, 200, 200, 200, 178, 200, 200, 178, 200, 200, 178, 178, 200, 200, 178, 200, 200, 200, 178, 200, 178, 178, 200, 200, 200, 200, 200, 200, 200},
                {178, 178, 178, 178, 200, 178, 200, 200, 178, 200, 178, 200, 200, 200, 178, 200, 178, 178, 178, 200, 200, 200, 200, 178, 178, 178, 178, 200, 200, 178, 178, 200, 200, 178, 178, 178, 200, 178, 200, 200, 178, 200, 200, 200, 200, 178, 200, 200},
            };
            printf("\n\n\n");
            for (i = 0; i < 7; i++) {
                printf("\t  ");
                for (j = 0; j < 57; j++) {
                    if (si[i][j] == 178)
                        printf("%c", k);
                    else
                        printf(" ");
                }
                printf("\n");
            }
            printf("\n\n");
            _sleep(3000);
            system("cls");
            menu();
        }
        teclas();
        foguetar();
        jscore();
        cagar();
        cagando();
        movimento();
    };
}

int main() {
    space i;
    i.menu();
}
